/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Flow.java
 *
 * Created on 19-giu-2009, 15.47.02
 */

package freimapgsoc;

import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author stefano
 */
public class Flow extends javax.swing.JFrame {

    /** Creates new form Flow */
    public Flow() {

        initComponents();
        /** Creates new form example1 */
        System.out.println("After initComponents");
        y_of_x = new double[n_points];
        x = new double[n_points];
        XYSeries series = new XYSeries("Cos(x) versus x");
        for (int i = 0;i< n_points;i++){//calculate the data to be plotted
                y_of_x[i] = Math.cos(i*Math.PI/180);
                     series.add((double)i,y_of_x[i]) ;//add the computed values to the series
            }
            XYDataset dataset = new XYSeriesCollection(series);
            JFreeChart chart = ChartFactory.createXYLineChart("Cos(x) versus x", "x", "cos(x)", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, false, false);

            BufferedImage image = chart.createBufferedImage(400,500);
               jLabel1.setIcon(new ImageIcon(image));
                    this.setSize(500, 600);
}
    

    /**
	 * This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 * @return 
	 */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Flow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
public static int n_points = 500;
public static double[] y_of_x,x;//we will plot y(x) versus x
}
